package com.das.mechanic_base.widget;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;

import com.das.mechanic_base.R;
import com.das.mechanic_base.base.X3BaseBottomSheetDialog;
import com.das.mechanic_base.utils.X3ToastUtils;

/**
 * 接车单详情-服务状态-转发
 */
public class X3BottomForwardDialog extends X3BaseBottomSheetDialog implements View.OnClickListener {

    String serviceUrl ;

    LinearLayout ll_url;
    LinearLayout ll_qr;

    public X3BottomForwardDialog(@NonNull Context context,String serviceUrl) {
        super(context);
        this.serviceUrl = serviceUrl;
    }

    @Override
    protected boolean getDialogCancel() {
        return false;
    }

    @Override
    protected void initView() {
        ll_url = getView(R.id.ll_url);
        ll_qr = getView(R.id.ll_qr);

        ll_url.setOnClickListener(this);
        ll_qr.setOnClickListener(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.x3_bottom_forward_dialog;
    }

    private void copy2Clipboard(String content) {
        ClipboardManager clipboard = (ClipboardManager) this.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
        //创建ClipData对象
        //第一个参数只是一个标记，随便传入。
        //第二个参数是要复制到剪贴版的内容
        ClipData clip = ClipData.newPlainText("content", content);
        //传入clipData对象.将文本内容放到系统剪贴板里。
        clipboard.setPrimaryClip(clip);
        String tip = "";
        tip = this.getContext().getString(R.string.x3_car_detail_url_copyed);
        X3ToastUtils.showMessage(tip);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.ll_url){
            copy2Clipboard(serviceUrl);
        } else if (v.getId() == R.id.ll_qr){
            X3BottomForwardQRDialog  qrDialog = new X3BottomForwardQRDialog(this.getContext(),serviceUrl);
            qrDialog.show();
        }
    }

}
